var express = require('express');
var router = express.Router();

var index = require('./admin/index');
var login = require('./admin/login');
var register= require('./admin/register');
var article = require('./admin/article');
var product = require('./admin/product');
var order = require('./admin/order');
var user=require("./admin/user");

var session = require("express-session");  /*锟斤拷锟斤拷session*/

//锟斤拷锟斤拷session锟叫硷拷锟?
router.use(session({
  secret: 'keyboard cat',  /*锟斤拷锟杰凤拷式*/
  resave: false,
  saveUninitialized: true
}));
var Host = "";

router.use(function (req, res, next) {
  Host = "http://" + req.headers.host;
  next();
})
router.get('/',function(req,res){
    res.render('admin/login',{
      host:Host
    })
})

router.use(function(req,res,next){
  if(req.url!='/login' && req.url!='/login/doLogin'){
    if(session.userinfo){
      next();
    }else{
      res.redirect('/admin/login');
    }
  }else{
    next();
  }
})


/* GET users listing. */


router.use('/index',index)

router.use('/article',article)

router.use('/product',product)

router.use('/login',login);
router.use('/register',register);


router.use('/order',order)

router.use("/user",user);

module.exports = router;
